import 'package:flutter/material.dart';
import 'package:situation/app/router/router_name.dart';
import 'package:situation/data/request/intell_request.dart';
import 'package:situation/domain/intell/IntellCategory.dart';
import 'package:situation/shared/util/util_location.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';

import 'state.dart';

class PublishIndexController extends GetxController
    with GetTickerProviderStateMixin {
  final PublishIndexState state = PublishIndexState();

  List<String> moreList = [];

  late TabController tabController;
  late PageController pageController;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    tabController = TabController(length: 3, vsync: this);
    pageController = PageController(initialPage: 0, keepPage: true);
    initIntellCategory();
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  void initIntellCategory() async {
    IntellRequest.getIntellCategory().then((value) {
      state.intellCategoryList = value;
      for (var i = 0; i < state.intellCategoryList.length; i++) {
        if (i > 8) {
          moreList.add(state.intellCategoryList[i].name);
        }
      }
    });
  }

  void intellCategoryOnTap(int index) {
    IntellCategory intellCategory = state.intellCategoryList[index];
    print(intellCategory);
    Get.toNamed(RouterName.publishIntell, arguments: intellCategory);
  }

  void toPublish(List selected) {
    int index = selected[0] + 9;
    IntellCategory intellCategory = state.intellCategoryList[index];
    Get.toNamed(RouterName.publishIntell, arguments: intellCategory);
  }
}
